import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param str string字符串 
     * @param pattern string字符串 
     * @return bool布尔型
     */

    public boolean match (String str, String pattern) {
        // write code here

        int lenA = str.length();
        int lenB = pattern.length();
        boolean[][] dp = new boolean[lenA +1][lenB + 1];

        dp[0][0] = true;

        for (int i = 0; i <= lenA; i++) {
            for (int j = 0; j <= lenB; j++) {
                if (j == 0) {
                    dp[i][j] = (i == 0);
                }
                else {
                    if (pattern.charAt(j - 1) != '*') {
                        if (i > 0 && (pattern.charAt(j - 1) == str.charAt(i - 1) || pattern.charAt(j - 1) == '.')) {
                            dp[i][j] = dp[i - 1][j - 1];
                        }
                    }
                    else {
                        if (j >= 2) {
                            dp[i][j] |= dp[i][j - 2];
                        }
                        if (i >= 1 && j >= 2 &&(str.charAt(i - 1) == pattern.charAt(j - 2) || pattern.charAt(j - 2) == '.')) {
                            dp[i][j] |= dp[i - 1][j];
                        }
                    }
                }
            }
        }

        return dp[lenA][lenB];
    }
}